package com.zbw.common.controller;


import com.zbw.common.entity.User;
import com.zbw.common.entity.UserBuyRecord;
import com.zbw.common.service.FrontUserService;
import com.zbw.common.vo.UserDetails;
import io.github.xxyopen.model.resp.RestResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
@RequiredArgsConstructor
@Slf4j
public class FrontController {

    private  final FrontUserService frontUserService;
//    @RequestMapping("login")
    @RequestMapping("login")
    public UserDetails login(@RequestBody User user){


        return frontUserService.login(user);
    }
    @RequestMapping("register")
    public UserDetails register(@RequestBody User user){

        return frontUserService.register(user);
    }
    @RequestMapping("queryIsInShelf")
    public Boolean queryIsInShelf(Long userId,  Long bookId){

        return frontUserService.queryIsInShelf(userId,bookId);
    }
    @RequestMapping("addToBookShelf")
    public void addToBookShelf(Long userId,  Long bookId, Long preContentId)
    {
        frontUserService.addToBookShelf(userId,bookId,preContentId);
    }
    @RequestMapping("removeFromBookShelf")
    public void removeFromBookShelf(Long userId,  Long bookId)
    {
        frontUserService.removeFromBookShelf( userId,   bookId);
    }
//    @RequestMapping("listBookShelfByPage")
//    public PageBean<BookShelfVO> listBookShelfByPage(Long userId,  Integer page,  Integer pageSize){
//
//        return frontUserService.listBookShelfByPage(userId,page,pageSize);
//    }
    @RequestMapping("addReadHistory")
    public void addReadHistory(Long userId,  Long bookId,  Long preContentId)
    {
        frontUserService.addReadHistory(userId,bookId,preContentId);
    }

    @RequestMapping("addFeedBack")
    public void addFeedBack(Long userId,  String content)
    {
        frontUserService.addFeedBack(userId,content);
    }

    @RequestMapping("userInfo")
    public User userInfo(Long userId)
    {
        return frontUserService.userInfo(userId);
    }

    @RequestMapping("updateUserInfo")
    public void updateUserInfo(Long userId,@RequestBody User user){
        frontUserService.updateUserInfo(userId,user);
    }

    @RequestMapping("updatePassword")
    public RestResult<?> updatePassword(Long userId, String oldPassword, String newPassword){

       return frontUserService.updatePassword(userId,oldPassword,newPassword);
    }

    @RequestMapping("queryIsBuyBookIndex")
    public boolean queryIsBuyBookIndex(Long id,  Long bookIndexId){

        return frontUserService.queryIsBuyBookIndex(id,bookIndexId);

    }

    @RequestMapping("buyBookIndex")
    RestResult<?> buyBookIndex(Long id,@RequestBody  UserBuyRecord buyRecord){

        return frontUserService.buyBookIndex(id,buyRecord);
    }
    @RequestMapping("addAmount")
    void addAmount(Long userId,  int totalAmount){

         frontUserService.addAmount(userId,totalAmount);
    }



}
